﻿using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;


Serve.Run(services =>
{
    services.AddSchedule(options =>
    {

        var triggerBuilder = Triggers.Secondly()
            .SetTriggerId("triggerId1")
            .SetTriggerType<CronTrigger>()
            .SetEndTime(DateTime.Now.AddSeconds(10));

        options.AddJob<MyJob>("jobId1", triggerBuilder);
    });
});
[DynamicApiController]
public class HelloService
{
    private readonly ISchedulerFactory _schedulerFactory;
    public HelloService(ISchedulerFactory schedulerFactory)
    {
        _schedulerFactory = schedulerFactory;
    }
    public void change() {

        _schedulerFactory.TryGetJob("jobId1", out var scheduler);
        var scheduleResult = scheduler.TryUpdateTrigger("triggerId1", triggerBuilder =>
        {
            triggerBuilder.SetEndTime(null);
        }, out var trigger);
        _schedulerFactory.RunJob("jobId1");

    }
}



public class MyJob : IJob
{
    private readonly ILogger<MyJob> _logger;
    public MyJob(ILogger<MyJob> logger)
    {
        _logger = logger;
    }
    public Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
    {
        _logger.LogInformation($"{context}");
        return Task.CompletedTask;
    }
}
